package com.xunge.mapper;

import com.xunge.pojo.HomeworkSubmission;
import com.xunge.pojo.HomeworkSubmissionQueryParam;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface HomeworkSubmissionMapper {

    /**
     * 分页查询作业提交信息
     */
    List<HomeworkSubmission> list(HomeworkSubmissionQueryParam homeworkSubmissionQueryParam);

    /**
     * 新增作业提交
     */
    @Insert("insert into homework_submission(homework_id, student_id, content, file_url, score, comment, submit_time, create_time, update_time) " +
            "values(#{homeworkId}, #{studentId}, #{content}, #{fileUrl}, #{score}, #{comment}, now(), now(), now())")
    void insert(HomeworkSubmission homeworkSubmission);

    /**
     * 根据ID查询作业提交
     */
    @Select("select * from homework_submission where id = #{id}")
    HomeworkSubmission getById(Integer id);

    /**
     * 根据ID修改作业提交
     */
    void update(HomeworkSubmission homeworkSubmission);

    /**
     * 根据ID删除作业提交
     */
    @Delete("delete from homework_submission where id = #{id}")
    void deleteById(Integer id);

    /**
     * 批量删除作业提交
     */
    void deleteByIds(List<Integer> ids);

    /**
     * 根据作业ID查询提交记录
     */
    @Select("select * from homework_submission where homework_id = #{homeworkId}")
    List<HomeworkSubmission> getByHomeworkId(Integer homeworkId);

    /**
     * 根据学生ID查询提交记录
     */
    @Select("select * from homework_submission where student_id = #{studentId}")
    List<HomeworkSubmission> getByStudentId(Integer studentId);

    /**
     * 根据作业ID和学生ID查询提交记录
     */
    @Select("select * from homework_submission where homework_id = #{homeworkId} and student_id = #{studentId}")
    HomeworkSubmission getByHomeworkIdAndStudentId(Integer homeworkId, Integer studentId);
} 